package com.wang.tool.delivery;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wang.tool.delivery.cache.module.ModuleBaseInfo;
import com.wang.tool.delivery.cache.module.ModuleMetaInfo;
import com.wang.tool.delivery.cache.page.PageBaseInfo;
import com.wang.tool.delivery.cache.page.PageMetaInfo;
import com.wang.tool.delivery.cache.page.RenderRangeModeEnum;
import com.wang.tool.delivery.cache.resource.ResourceMetaInfo;
import com.wang.tool.delivery.res.Entity;
import com.wang.tool.delivery.res.ModuleView;
import com.wang.tool.delivery.res.PageView;
import com.wang.tool.delivery.res.ResourceView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author shaopeng
 * @Date 2022/8/18
 * @Version 1.0
 */
public class DeliveryTest {


    public static void main(String[] args) {

        PageView pageView = new PageView();
        pageView.setPageId("123");
//        pageView.setExtInfo(new JSONObject());

        PageMetaInfo pageMetaInfo = new PageMetaInfo();
        pageMetaInfo.setDefRenderRangeMode(RenderRangeModeEnum.ALL.getCode());
        pageMetaInfo.setSpmA("a.1");
        pageMetaInfo.setSpmB("b.3");
        pageView.setMetaInfo(pageMetaInfo);

        PageBaseInfo pageBaseInfo = new PageBaseInfo();
        pageBaseInfo.setTitle("页面标题");
        pageBaseInfo.setBackground("页面背景图");

        pageView.setBaseInfo(pageBaseInfo);
        ArrayList<ModuleView> modules = new ArrayList<>();
        pageView.setModules(modules);



        ModuleView moduleView2 = new ModuleView();
        modules.add(moduleView2);
        moduleView2.setOrder(1);
        moduleView2.setModuleId("12345");
        moduleView2.setModuleCode("@alisearch");
//        moduleView.setExtInfo(new JSONObject());
        moduleView2.setModuleName("搜索");
        ModuleBaseInfo moduleBaseInfo2 = new ModuleBaseInfo();
        moduleBaseInfo2.setTitle("搜索");
        moduleBaseInfo2.setSubTitle("快来搜啊");
        moduleBaseInfo2.setSpmC("c.145");
        moduleView2.setBaseInfo(moduleBaseInfo2);

        ModuleMetaInfo moduleMetaInfo2 = new ModuleMetaInfo();
        moduleMetaInfo2.setModuleStyle("SEARCH");
        moduleMetaInfo2.setLowVersion("1");


        moduleView2.setMetaInfo(moduleMetaInfo2);


        Map<String, ResourceView> resources2 = new HashMap<>();
        moduleView2.setResources(resources2);

        ResourceView tab1View2 = new ResourceView();
        resources2.put("words", tab1View2);
        tab1View2.setOrder(1);
        tab1View2.setResourceId("1236");
        tab1View2.setResourceCode("words");
//        tab1View.setExtInfo(new JSONObject());
//        ResourceBaseInfo resourceBaseInfo2 = new ResourceBaseInfo();
//        resourceBaseInfo2.setTitle("");
//        tab1View2.setBaseInfo(resourceBaseInfo2);
        ArrayList<String> plan2Ids = new ArrayList<>();
        plan2Ids.add("1234");
        tab1View2.setPlanIds(plan2Ids);

        ResourceMetaInfo resourceMetaInfo2 = new ResourceMetaInfo();
        tab1View2.setMetaInfo(resourceMetaInfo2);

        ArrayList<Entity> entities2 = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Entity e = new Entity();
            e.setId("156744"+i);
            e.setType("WORDS");
            JSONObject data = new JSONObject();
            data.put("words", "156744"+i);
            data.put("jumpUrl", "http://csbdchdscds?cd=1"+i);
            e.setData(data);
            entities2.add(e);
        }
        tab1View2.setEntities(entities2);

        ResourceView tab1View3 = new ResourceView();
        resources2.put("dwc", tab1View3);
        tab1View3.setOrder(1);
        tab1View3.setResourceId("12365");
        tab1View3.setResourceCode("dwc");
//        tab1View.setExtInfo(new JSONObject());
//        ResourceBaseInfo resourceBaseInfo3 = new ResourceBaseInfo();
//        resourceBaseInfo3.setTitle("底纹词");
//        tab1View3.setBaseInfo(resourceBaseInfo3);
        ArrayList<String> plan3Ids = new ArrayList<>();
        plan3Ids.add("1234");
        tab1View3.setPlanIds(plan3Ids);

        ResourceMetaInfo resourceMetaInfo3 = new ResourceMetaInfo();
        tab1View3.setMetaInfo(resourceMetaInfo3);

        ArrayList<Entity> entities3 = new ArrayList<>();
        for (int i = 0; i < 1; i++) {
            Entity e = new Entity();
            e.setId("156744"+i);
            e.setType("DWC");
            JSONObject data = new JSONObject();
            data.put("dwc", "搜索更精彩");
            e.setData(data);
            entities2.add(e);
        }
        tab1View3.setEntities(entities3);



        ModuleView moduleView = new ModuleView();
        moduleView.setOrder(0);
        moduleView.setModuleId("1234");
        moduleView.setModuleCode("@alifeeds");
//        moduleView.setExtInfo(new JSONObject());
        moduleView.setModuleName("商品feeds");
        ModuleBaseInfo moduleBaseInfo = new ModuleBaseInfo();
        moduleBaseInfo.setTitle("区块标题");
        moduleBaseInfo.setSubTitle("区块副标题");
        moduleBaseInfo.setSpmC("c.143");
        moduleView.setBaseInfo(moduleBaseInfo);

        ModuleMetaInfo moduleMetaInfo = new ModuleMetaInfo();
        moduleMetaInfo.setModuleStyle("TAB_FEEDS");
        moduleMetaInfo.setLowVersion("1.1");


        moduleView.setMetaInfo(moduleMetaInfo);


        Map<String, ResourceView> resources = new HashMap<>();
        moduleView.setResources(resources);

        ResourceView tab1View = new ResourceView();
        resources.put("tab1", tab1View);
        tab1View.setOrder(1);
        tab1View.setResourceId("123");
        tab1View.setResourceCode("tab1");
//        tab1View.setExtInfo(new JSONObject());
//        ResourceBaseInfo resourceBaseInfo = new ResourceBaseInfo();
//        resourceBaseInfo.setTitle("");
//        tab1View.setBaseInfo(resourceBaseInfo);
        ArrayList<String> planIds = new ArrayList<>();
        planIds.add("1234");
        tab1View.setPlanIds(planIds);

        ResourceMetaInfo resourceMetaInfo = new ResourceMetaInfo();
        tab1View.setMetaInfo(resourceMetaInfo);

        ArrayList<Entity> entities = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            Entity e = new Entity();
            e.setId("156743"+i);
            e.setType("ITEM");
            JSONObject data = new JSONObject();
            data.put("itemId", "156743"+i);
            data.put("itemName", "洗脚按摩"+i);
            data.put("price", "199.0");
            data.put("originalPrice", "299.0");
            e.setData(data);
            entities.add(e);
        }
        tab1View.setEntities(entities);


        ResourceView tab2View = new ResourceView();
        resources.put("tab2", tab2View);

        tab2View.setOrder(2);
        tab2View.setResourceId("124");
        tab2View.setResourceCode("tab2");
//        tab2View.setExtInfo(new JSONObject());
//        PageInfo pageInfo2 = new PageInfo();
//        pageInfo2.setToken("csdcds_20220817115216_f9708ac9");
//        tab2View.setPageInfo(pageInfo2);
//        ResourceBaseInfo resourceBaseInfo4 = new ResourceBaseInfo();
//        resourceBaseInfo4.setTitle("资源位标题2");
//        tab2View.setBaseInfo(resourceBaseInfo4);
        ArrayList<String> planIds2 = new ArrayList<>();
        planIds2.add("1235");
        tab2View.setPlanIds(planIds2);

        ResourceMetaInfo resourceMetaInfo4 = new ResourceMetaInfo();
        tab2View.setMetaInfo(resourceMetaInfo4);




        modules.add(moduleView);

        System.out.println(JSON.toJSONString(pageView));


    }


}
